<?php

namespace App\Observers;

use App\Models\Chapter;

class ChapterObserver
{
    /**
     * Handle the chapter "created" event.
     *
     * @param  \App\Models\Chapter $chapter
     * @return void
     */
    public function creating(Chapter $chapter)
    {
        $chapter->user_id = auth()->id();
        if (has_adult_content($chapter->content)) {
            $chapter->status = $chapter::STATUS_ADULT;
        }
    }

    /**
     * Handle the chapter "updated" event.
     *
     * @param  \App\Models\Chapter $chapter
     * @return void
     */
    public function updating(Chapter $chapter)
    {
        if (has_adult_content($chapter->content)) {
            $chapter->status = $chapter::STATUS_ADULT;
        }
    }

    /**
     * Handle the chapter "deleted" event.
     *
     * @param  \App\Models\Chapter $chapter
     * @return void
     */
    public function deleted(Chapter $chapter)
    {
        //
    }

    /**
     * Handle the chapter "restored" event.
     *
     * @param  \App\Models\Chapter $chapter
     * @return void
     */
    public function restored(Chapter $chapter)
    {
        //
    }

    /**
     * Handle the chapter "force deleted" event.
     *
     * @param  \App\Models\Chapter $chapter
     * @return void
     */
    public function forceDeleted(Chapter $chapter)
    {
        //
    }
}
